﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class DelayToInvoke : MonoBehaviour
{
    private static MonoBehaviour behaviour;
    public delegate void Task();

    public static void Schedule(MonoBehaviour _behaviour, float delay, Task task)
    {
        behaviour = _behaviour;
        behaviour.StartCoroutine(DoTask(task, delay));
    }

    private static IEnumerator DoTask(Task task, float delay)
    {
        yield return new WaitForSeconds(delay);
        task();
    }
}
    public class HowToUse : MonoBehaviour
    {
        private void Start()
        {
            howToUse(1f);
        }
        private void howToUse(float time)
        {
            DelayToInvoke.Schedule(this, time, () =>
                {
                    print("等待time做某事");
                });
        }
    }

